package com.southwind.controller;


import com.southwind.entity.TbAssetRole;
import com.southwind.form.RuleForm;
import com.southwind.form.SearchForm;
import com.southwind.service.TbAdminService;
import com.southwind.service.TbAssetRoleService;
import com.southwind.util.ResultVOUtil;
import com.southwind.vo.PageVO;
import com.southwind.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fjh
 * @since 2024-01-08
 */
@RestController
@RequestMapping("/tbAssetRole")
public class TbAssetRoleController {
    @Autowired
    private TbAssetRoleService tbAssetRoleService;

    @GetMapping("/login")
    public ResultVO login(RuleForm ruleForm) {
        ResultVO resultVO=this.tbAssetRoleService.login(ruleForm);
        return resultVO;
    }

    @PostMapping("/save")
    public ResultVO save(@RequestBody TbAssetRole tbAssetRole) {
        boolean save = this.tbAssetRoleService.save(tbAssetRole);
        if (!save) return ResultVOUtil.fail();
        return ResultVOUtil.success(null);
    }

    @GetMapping("/list/{page}/{size}")
    public ResultVO list(@PathVariable("page") Integer page,@PathVariable("size") Integer size){
        PageVO pageVO = this.tbAssetRoleService.list(page, size);
        return ResultVOUtil.success(pageVO);
    }
    @GetMapping("/search")
    public ResultVO search(SearchForm searchForm){
        PageVO pageVO = this.tbAssetRoleService.search(searchForm);
        return ResultVOUtil.success(pageVO);
    }

    @GetMapping("/findById/{id}")
    public ResultVO findById(@PathVariable("id") Integer id){
        TbAssetRole tbAssetRole = this.tbAssetRoleService.getById(id);
        return ResultVOUtil.success(tbAssetRole);
    }

    @PutMapping("/update")
    public ResultVO update(@RequestBody TbAssetRole tbAssetRole){
        boolean update = this.tbAssetRoleService.updateById(tbAssetRole);
        if(!update) return ResultVOUtil.fail();
        return ResultVOUtil.success(null);
    }

    @DeleteMapping("/deleteById/{id}")
    public ResultVO deleteById(@PathVariable("id") Integer id){
        boolean remove = this.tbAssetRoleService.removeById(id);
        if(!remove) return ResultVOUtil.fail();
        return ResultVOUtil.success(null);
    }
    @GetMapping("/list")
    public ResultVO list(){
        List<TbAssetRole> tbAssetRoleList = this.tbAssetRoleService.list();
        return ResultVOUtil.success(tbAssetRoleList);
    }
}

